extends IEventBehavior


class_name HitSplit
"""
分裂效果
"""


## 是否附加效果
@export var is_apply_effect: bool = false
## 分裂的角度
@export_range(0, 360, 1, "radians") var split_angle: float = deg_to_rad(10)


func support() -> Array:
    return [0, CharacterUnit.Event.ON_HIT_EXECUTE]

## 处理子弹初始化事件
func do_event(character: CharacterComponent, v: EffectValue, e: CharacterEvent) -> void:
    var source: ProjectileResource = e.meta.source
    var angles: Array = ShapeDraw.get_split_angles(v.value, split_angle)
    var start_angle: float = source.start_direction.angle()
    var projectile: Projectile = e.meta.projectile
    for i in range(len(angles)):
        var value: float = angles[i] + start_angle
        source.start_direction = Vector2.from_angle(value)
        var b: Projectile = projectile.weapon.spawn(source)
        if is_apply_effect:
            b.processor = projectile.processor.clone()
    e.cancel()
